{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "0759db13",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "# 提取类型与得分投票的关系\n",
    "df = pd.read_csv(r\"..\\csv\\preprocessed2.csv\")\n",
    "genre_rating_votes = df.loc[:,\"is_Action\":\"num_votes\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "dd319231",
   "metadata": {},
   "outputs": [],
   "source": [
    "cols = genre_rating_votes.columns[0:-3]\n",
    "idx = genre_rating_votes.columns[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "cf0a3e0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "summary = pd.DataFrame(index = idx,columns = cols)\n",
    "count = pd.DataFrame(index = [\"count\"],columns = cols)\n",
    "summary = pd.concat((summary,count),axis = 0)\n",
    "summary[:] = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "c5fd2bed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>is_Action</th>\n",
       "      <th>is_Adventure</th>\n",
       "      <th>is_Animation</th>\n",
       "      <th>is_Biography</th>\n",
       "      <th>is_Comedy</th>\n",
       "      <th>is_Crime</th>\n",
       "      <th>is_Documentary</th>\n",
       "      <th>is_Drama</th>\n",
       "      <th>is_Family</th>\n",
       "      <th>is_Fantasy</th>\n",
       "      <th>...</th>\n",
       "      <th>is_Mystery</th>\n",
       "      <th>is_Reality-TV</th>\n",
       "      <th>is_Romance</th>\n",
       "      <th>is_Sci-Fi</th>\n",
       "      <th>is_Short</th>\n",
       "      <th>is_Sport</th>\n",
       "      <th>is_Talk-Show</th>\n",
       "      <th>is_Thriller</th>\n",
       "      <th>is_War</th>\n",
       "      <th>is_Western</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>average_rating</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>num_votes</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 25 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               is_Action is_Adventure is_Animation is_Biography is_Comedy  \\\n",
       "average_rating         0            0            0            0         0   \n",
       "num_votes              0            0            0            0         0   \n",
       "count                  0            0            0            0         0   \n",
       "\n",
       "               is_Crime is_Documentary is_Drama is_Family is_Fantasy  ...  \\\n",
       "average_rating        0              0        0         0          0  ...   \n",
       "num_votes             0              0        0         0          0  ...   \n",
       "count                 0              0        0         0          0  ...   \n",
       "\n",
       "               is_Mystery is_Reality-TV is_Romance is_Sci-Fi is_Short  \\\n",
       "average_rating          0             0          0         0        0   \n",
       "num_votes               0             0          0         0        0   \n",
       "count                   0             0          0         0        0   \n",
       "\n",
       "               is_Sport is_Talk-Show is_Thriller is_War is_Western  \n",
       "average_rating        0            0           0      0          0  \n",
       "num_votes             0            0           0      0          0  \n",
       "count                 0            0           0      0          0  \n",
       "\n",
       "[3 rows x 25 columns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a343f3b",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(len(genre_rating_votes)):\n",
    "    row = genre_rating_votes.iloc[i]\n",
    "    for col in cols:\n",
    "        if row[col] == 1:\n",
    "            summary.loc[\"average_rating\",col]+=row[\"average_rating\"]\n",
    "            summary.loc[\"num_votes\",col]+=row[\"num_votes\"]\n",
    "            summary.loc[\"count\",col]+=1\n",
    "summary = summary.transpose()\n",
    "summary[\"total_average_rating\"] = summay[\"aver\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "c4809e71",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>average_rating</th>\n",
       "      <th>num_votes</th>\n",
       "      <th>count</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>is_Action</th>\n",
       "      <td>172.4</td>\n",
       "      <td>42669.0</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Adventure</th>\n",
       "      <td>195.6</td>\n",
       "      <td>226864.0</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Animation</th>\n",
       "      <td>194.3</td>\n",
       "      <td>130285.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Biography</th>\n",
       "      <td>116.7</td>\n",
       "      <td>11836.0</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Comedy</th>\n",
       "      <td>1682.0</td>\n",
       "      <td>1179523.0</td>\n",
       "      <td>274</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Crime</th>\n",
       "      <td>201.5</td>\n",
       "      <td>99971.0</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Documentary</th>\n",
       "      <td>716.7</td>\n",
       "      <td>35606.0</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Drama</th>\n",
       "      <td>3075.9</td>\n",
       "      <td>1293789.0</td>\n",
       "      <td>489</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Family</th>\n",
       "      <td>423.8</td>\n",
       "      <td>56432.0</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Fantasy</th>\n",
       "      <td>186.0</td>\n",
       "      <td>44167.0</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Film-Noir</th>\n",
       "      <td>12.7</td>\n",
       "      <td>1124.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_History</th>\n",
       "      <td>115.4</td>\n",
       "      <td>19922.0</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Horror</th>\n",
       "      <td>230.8</td>\n",
       "      <td>324010.0</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Music</th>\n",
       "      <td>332.5</td>\n",
       "      <td>27218.0</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Musical</th>\n",
       "      <td>99.4</td>\n",
       "      <td>18584.0</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Mystery</th>\n",
       "      <td>192.8</td>\n",
       "      <td>338922.0</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Reality-TV</th>\n",
       "      <td>6.8</td>\n",
       "      <td>16.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Romance</th>\n",
       "      <td>1169.5</td>\n",
       "      <td>1183107.0</td>\n",
       "      <td>190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Sci-Fi</th>\n",
       "      <td>67.3</td>\n",
       "      <td>4309.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Short</th>\n",
       "      <td>116.1</td>\n",
       "      <td>1382.0</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Sport</th>\n",
       "      <td>168.1</td>\n",
       "      <td>15151.0</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Talk-Show</th>\n",
       "      <td>7.8</td>\n",
       "      <td>16.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Thriller</th>\n",
       "      <td>191.6</td>\n",
       "      <td>178680.0</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_War</th>\n",
       "      <td>101.0</td>\n",
       "      <td>14495.0</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>is_Western</th>\n",
       "      <td>16.9</td>\n",
       "      <td>662.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               average_rating  num_votes count\n",
       "is_Action               172.4    42669.0    29\n",
       "is_Adventure            195.6   226864.0    32\n",
       "is_Animation            194.3   130285.0    30\n",
       "is_Biography            116.7    11836.0    17\n",
       "is_Comedy              1682.0  1179523.0   274\n",
       "is_Crime                201.5    99971.0    33\n",
       "is_Documentary          716.7    35606.0    98\n",
       "is_Drama               3075.9  1293789.0   489\n",
       "is_Family               423.8    56432.0    70\n",
       "is_Fantasy              186.0    44167.0    30\n",
       "is_Film-Noir             12.7     1124.0     2\n",
       "is_History              115.4    19922.0    17\n",
       "is_Horror               230.8   324010.0    48\n",
       "is_Music                332.5    27218.0    48\n",
       "is_Musical               99.4    18584.0    17\n",
       "is_Mystery              192.8   338922.0    33\n",
       "is_Reality-TV             6.8       16.0     1\n",
       "is_Romance             1169.5  1183107.0   190\n",
       "is_Sci-Fi                67.3     4309.0    10\n",
       "is_Short                116.1     1382.0    18\n",
       "is_Sport                168.1    15151.0    26\n",
       "is_Talk-Show              7.8       16.0     1\n",
       "is_Thriller             191.6   178680.0    36\n",
       "is_War                  101.0    14495.0    15\n",
       "is_Western               16.9      662.0     3"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "eda32cd3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.6333"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "round(5.633333333333333,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0adf8711",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "myenv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
